
import { defineStore } from "pinia";
import { getUserInfoDetail } from './../api/api';

export const useUserStore = defineStore('user', {
    state: () => {
        return {
            token: "",
            userId: "",
            userInfo: null,
        };
    },
    actions: {
        clearUserInfo() {
            this.userInfo = null;
            this.userId = ''
            this.token = ''
        },
        todosetToken(payload: { token: string; userId: string }) {
            this.token = payload.token;
            this.userId = payload.userId;
        },
        async getuserInfoAsync() {
            let res: any = await getUserInfoDetail()
            if (res.status == 200) {
                this.userInfo = res.data.userInfo;
            } else {
                this.userInfo = null;
            }
        }
    },
})